#!/usr/bin/env python

import cgi
import minifb

_FbApiKey = "USE YOUR OWN! :)"
_FbSecret = minifb.FacebookSecret("USE YOUR OWN! :)")

class User:

    def __init__(self, webcom):
        self.username = webcom.get("user", "Unknown user!")

    def __str__(self):
        return self.username


class WebCommunication:

    def __init__(self):
        print "Content-Type: text/html\n\n"
        self.form = cgi.FieldStorage()

    def get(self, key, default):
        if self.form.has_key(key):
            return self.form[key].value
        else:
            return default

    def writeln(self, text):
        print text + "<br>"

    def write(self, text):
        print text

class Form:

    def __init__(self, keywords_and_types):
        self.markup = '<form action="" method="get">'
        for key, value in keywords_and_types.items():
            self.markup += '<input name="' + key + '" type="' + value + '" size="30" value="">'
        self.markup += '<input name="submit" type="submit" value="Submit">'
        self.markup += '</form>'

    def __str__(self):
        return self.markup

class Dashboard:

    def __init__(self):
        self.markup = """<fb:dashboard>
  <fb:action href="?id=1234567">My Book Reviews</fb:action>
  <fb:action href="new.php">Write a New Review</fb:action>
  <fb:help href="help.php" title="Need help">Help</fb:help>
  <fb:create-button href="new.php">Write a New Review</fb:create-button>
</fb:dashboard>"""

    def __str__(self):
        return self.markup

def main():
    wc = WebCommunication()
    try:
        wc.writeln(wc.get("profiletext", "no profiletext"))
        #wc.writeln(str(User(wc)))
        #wc.writeln(str(Form({"profiletext":"text"})))
        wc.writeln(str(Dashboard()))
        wc.writeln("done.")
    except Exception, e:
        wc.writeln(e)
    wc.writeln(str(dir(minifb)))

main()

"""
if (isset($_REQUEST['profiletext'])) {
  $facebook->api_client->profile_setFBML($_REQUEST['profiletext'], $user);
  $facebook->redirect($facebook->get_facebook_url() . '/profile.php');
}
"""

#form = cgi.FieldStorage()
#if form.has_key("fb_sig_user"):
#    print form["fb_sig_user"]
#if (form.has_key("action") and form.has_key("name") \
#and form.has_key("age")):
#         if (form["action"].value == "display"):
#            display_data(form["name"].value, form["age"].value)
